package longrise.phone.com.bjjt_henan.compensate;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.FormParameter;
import com.longrise.android.FrameworkManager;
import com.longrise.android.ILFMsgListener;
import com.longrise.android.LFView;

import longrise.phone.com.bjjt_henan.MainActivity;
import longrise.phone.com.bjjt_henan.R;

/**
 * 保险报案，选择是否向保险公司报案，Created by Administrator on 2016/5/12.
 */

public class InsuranceReportChoiceView extends LFView implements View.OnClickListener, ILFMsgListener {
    private Context context = null;
    private View view = null;
    private Button bt_toinsurance;
    private EntityBean[] CreateAgreementbean;
    private String appCaseno;
    private LinearLayout hn_btn_back;
    private TextView tv_title;
    private String ifSingle = "-1";

    private String flag;

    public InsuranceReportChoiceView(Context c, EntityBean[] CreateAgreementbean, String appCaseno) {
        super(c);
        this.context = c;
        this.CreateAgreementbean = CreateAgreementbean;
        this.appCaseno = appCaseno;
    }

    public void setIfSingle(String ifSingle) {
        this.ifSingle = ifSingle;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter fp = new FormParameter();
        fp.setShowtitle(false);
        return fp;
    }

    @Override
    public void refresh() {

    }

    @Override
    public View getView() {
        return view;
    }

    @Override
    public void init() {
        initView();
        regEvent(true);
        this.addILFMsgListener(this);
        ((MainActivity) context).initHelpView(view, appCaseno);
    }

    private void initView() {
        view = View.inflate(context, R.layout.view_insurancereportchoiceview, null);
        bt_toinsurance = (Button) view.findViewById(R.id.bt_toinsurance);
        hn_btn_back = (LinearLayout) view.findViewById(R.id.hn_btn_back);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_title.setText("保险报案");
    }

    private void regEvent(boolean b) {
        if (null != bt_toinsurance) {
            bt_toinsurance.setOnClickListener(b ? this : null);
        }
        if (null != hn_btn_back) {
            hn_btn_back.setOnClickListener(b ? this : null);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_toinsurance:
                PromptAfterInsuranceReportView view = new PromptAfterInsuranceReportView(context, CreateAgreementbean,
                        appCaseno, ifSingle);
                if (TextUtils.equals("1", flag)) {
                    view.setTypes(2);
                }
                FrameworkManager.getInstance().showNewForm(context, view);
                break;
            case R.id.hn_btn_back:
                OnDestroy();
                closeForm();
                break;
            default:
                break;
        }
    }

    @Override
    public Object onLFMsg(int i, Object... objects) {
        if (i == -10) {//点击返回按键
            if (!TextUtils.equals(ifSingle, "0")) {
                //只能生成一次责任认定书
                ((MainActivity) context).backToMainView();
            }
        }
        return null;
    }


    @Override
    public void OnDestroy() {
        super.OnDestroy();
        regEvent(false);
        removeILFMsgListener(this);
        CreateAgreementbean = null;
        view = null;
    }
}
